package socket01;

public class camera
{
   private final String _raspistillPath = "/opt/vc/bin/raspistill";
   private final int _picTimeout = 1000;
   private final int _picQuality = 100;
   private int _picWidth = 1024;
   private int _picHeight = 768;
   private String _picName = "example.jpg";
   private String _picType = "jpg";

   // constructeur
   public void RaspiStill()
   {
      // rien pour l'instant
   }
  
   public void TakePicture()
   {
      try
      {
         // Determine the image type based on the file extension (or use the default).
         if (_picName.indexOf('.')!=-1)
        	 _picType = _picName.substring(_picName.lastIndexOf('.')+1);

         StringBuilder sb = new StringBuilder(_raspistillPath);

         //  no preview et burst mode.
         sb.append(" -n -bm");
         //  timeout.
         sb.append(" -t " + _picTimeout);
         sb.append(" -w " + _picWidth);
         sb.append(" -h " + _picHeight);
         sb.append(" -q " + _picQuality);
         sb.append(" -e " + _picType);
         sb.append(" -o " + _picName);

         // commande pour prendre la photo
         Runtime.getRuntime().exec(sb.toString());
         // pause pour la prise de vue
         Thread.sleep(_picTimeout);
      }
      catch (Exception e)
      {
         System.exit(e.hashCode());
      }
   }

   // surcharge
   public void TakePicture(String name, int width, int height)
   {
      _picName = name;
      _picWidth = width;
      _picHeight = height;
      TakePicture();
   }

   // surcharge
   public void TakePicture(String name)
   {
      TakePicture(name, _picWidth, _picHeight);
   }

   // surcharge
   public void TakePicture(int width, int height)
   {
      TakePicture(_picName, width, height);
   }
}